package org.bwf.study.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticSearchConfig {
    @Value("${elasticsearch.hostname}")
    private String hostName;
    @Value("${elasticsearch.port}")
    private int port;

    public static RequestOptions options = null;

    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        options = builder.build();
    }

    @Bean(name = "restHighLevelClient")
    public RestHighLevelClient restHighLevelClient() {

        return new RestHighLevelClient(
                RestClient.builder(new HttpHost(hostName, port, "http"))
        );
    }

}
